<!DOCTYPE html>
<html lang="pt-BR">
    <head>    
        <link href="style/farmacia.css" rel="stylesheet">
        <script src="script/farmacia.js" language="javascript"></script>
        <meta charset="UTF-8">
        <title>Farmácia do Arnaldo</title>
    </head>

    <body>
        <div id="cabecalho">
            <div id="cabecalhoIndex">
                <div id="title">
                    Farmácia do Arnaldo
                </div>
            </div>
        </div>
        <div id="conteudo">
            <div id="padding">
                <div id="info">
                    <?php                    
                    $sql = "SELECT COUNT(ID) FROM  funcionario";
                    $dbconn = mysql_connect('localhost', 'root', '') or die("MySQL: Não foi possível conectar-se ao servidor.");
                    mysql_select_db('drogaria', $dbconn) or die("Banco Inexistente!");
                    if (mysql_fetch_assoc(mysql_query($sql))['COUNT(ID)'] == 0) {
                        echo '<form action="view/cadastraAdmin.php" method="post">';
                        echo '<table align="center">';
                        echo '<tr><td>Primeiro acesso.</td><td> Insira uma senha!</td></tr>';
                        echo '<tr><td>Usuário: </td>';
                        echo '<td><input type = "text" name = "usuario" readonly value="admin" id = "readonly"></td></tr>';
                        echo "<td>Senha: </td>";
                        echo '<td><input type="password" name="senha" maxlength="16" required id="senhaID"></td>';
                        echo '<tr><td colspan="2" align="center"><input type="submit" value="Cadastrar"></tr>';
                        echo '</table></form>';
                        
                    } else {
                        if (isset($_GET['pw'])) {
                            echo "<div style='color:red'>";
                            echo "Usuário e/ou senha inválidos!";
                            echo "</div>";
                        }
                        echo '<form action="valida.php"  method="post">';
                        echo '<table align="center">';
                        echo '<tr><td>Usuário: </td>';
                        echo '<td><input type = "text" name = "usuario" required id = "usuarioID"></td></tr>';
                        echo "<td>Senha: </td>";
                        echo '<td><input type="password" name="senha" required id="senhaID"></td>';
                        echo '<tr><td colspan="2" align="center"><input type="submit" value="Entrar"></tr>';
                        echo '</table></form>';
                    }
                    ?>                            


                </div>
            </div>
        </div>
        <div id="rodape">
            Copyright (c) 2013 FarmáciaProgWeb.com. All rights reserved.
        </div>
    </body>
</html>
